const { addService, updateOneService, deleteOneService, findOneService } = require('../service/users')

const add = async ctx => {
  const { username = "123", password = "456" } = ctx.request.body
  const data = await addService(username, password)
  ctx.body = {
    code: 0,
    data
  }
}

const findOne = async ctx => {
  const { _id } = ctx.params
  const data = await findOneService(_id)
  ctx.body = {
    code: 0,
    data
  }
}

const updateOne = async ctx => {
  const { _id, username, password } = ctx.request.body
  const data = await updateOneService(_id, username, password)
  ctx.body = {
    code: 0,
    data
  }
}

const deleteOne = async ctx => {
  const { _id } = ctx.query
  const data = await deleteOneService(_id)
  ctx.body = {
    code: 0,
    data
  }
}

module.exports = {
  add,
  findOne,
  updateOne,
  deleteOne
}